/***************************************************************************************************
  *Copyright(C),2010-2016,Sumscope
  *FileName	:  system_time.h
  *Author	:  scofined.qi
  *Version	:  1.0
  *Date		:  2016/02/01
  *Desc		:  用于替换系统的<atltime.h>头文件中的CTime实现
  *Relation :  
  *Others	:  //其他内容说明
  *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
  *History	:  //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
***************************************************************************************************/
#pragma once

#include "../core.h"
#include "../typedefs.h"

namespace qb{
namespace base{

	typedef int64_t LONGLONG;
	typedef int64_t __time64_t;
	typedef int LONG;
	typedef unsigned short WORD;

	class S_CORE_EXPORT CTimeSpan
	{
	public:
		CTimeSpan() throw();
		CTimeSpan( __time64_t time ) throw();
		CTimeSpan( LONG lDays, int nHours, int nMins, int nSecs ) throw();

		LONGLONG GetDays() const throw();
		LONGLONG GetTotalHours() const throw();
		LONG GetHours() const throw();
		LONGLONG GetTotalMinutes() const throw();
		LONG GetMinutes() const throw();
		LONGLONG GetTotalSeconds() const throw();
		LONG GetSeconds() const throw();

		__time64_t GetTimeSpan() const throw();

		CTimeSpan operator+( CTimeSpan span ) const throw();
		CTimeSpan operator-( CTimeSpan span ) const throw();
		CTimeSpan& operator+=( CTimeSpan span ) throw();
		CTimeSpan& operator-=( CTimeSpan span ) throw();
		bool operator==( CTimeSpan span ) const throw();
		bool operator!=( CTimeSpan span ) const throw();
		bool operator<( CTimeSpan span ) const throw();
		bool operator>( CTimeSpan span ) const throw();
		bool operator<=( CTimeSpan span ) const throw();
		bool operator>=( CTimeSpan span ) const throw();

	private:
		__time64_t m_timeSpan;
	};
	class S_CORE_EXPORT CTime
	{
	public:
		CTime() throw();
		CTime( __time64_t time ) throw();
		CTime( int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
			int nDST = -1 );
		CTime( WORD wDosDate, WORD wDosTime, int nDST = -1 );

		CTime& operator=( __time64_t time ) throw();

		CTime& operator+=( CTimeSpan span ) throw();
		CTime& operator-=( CTimeSpan span ) throw();

		CTimeSpan operator-( CTime time ) const throw();
		CTime operator-( CTimeSpan span ) const throw();
		CTime operator+( CTimeSpan span ) const throw();

		bool operator==( CTime time ) const throw();
		bool operator!=( CTime time ) const throw();
		bool operator<( CTime time ) const throw();
		bool operator>( CTime time ) const throw();
		bool operator<=( CTime time ) const throw();
		bool operator>=( CTime time ) const throw();

		struct tm* GetGmtTm( struct tm* ptm ) const;
		struct tm* GetLocalTm( struct tm* ptm ) const;

		__time64_t GetTime() const throw();

		int GetYear() const;
		int GetMonth() const;
		int GetDay() const;
		int GetHour() const;
		int GetMinute() const;
		int GetSecond() const;
		int GetDayOfWeek() const;

		// formatting using "C" strftime
		//WideString Format( LPCTSTR pszFormat ) const;
		//WideString FormatGmt( LPCTSTR pszFormat ) const;
		//WideString Format( UINT nFormatID ) const;
		//WideString FormatGmt( UINT nFormatID ) const;

	private:
#ifdef CCORE_MAC
		time_t m_time;
#else
		__time64_t m_time;
#endif
	};




}//namespace base;
}//namespace qb;
